<?php
$page_title = 'eTAT: Survey';
$style = 'survey';
$script = 'survey';
require_once '../controller.php';
if(isset($params->copy)) {
	$instructor->copySurvey($params->copy);
	redirect('survey/');
}
if(isset($params->delete)) {
	$instructor->deleteSurvey($params->delete);
	redirect('survey/');
}
$surveys = $instructor->getAllSurveys();
require_once '../header.php';
?>
<h1>Surveys <?php print newBtn('create_survey','Create New Survey',array('type'=>'button','onclick'=>'window.location="createsurvey.php"','class'=>'right')); ?>
</h1>
<br>
<table cellpadding="2px" cellspacing="2px">
	<tr>
		<td width="650px"><strong>Survey Name</strong></td>
		<td width="150px"><strong>Date Created</strong></td>
		<td width="150px"><strong>Last Modified </strong></td>
		<td width="50px"><strong>Preview</strong></td>
		<td width="50px"><strong>Copy</strong></td>
		<td width="50px"><strong>Edit</strong></td>
		<td width="50px"><strong>Results</strong></td>
		<td width="50px"><strong>Send</strong></td>
		<td width="50px"><strong>Delete</strong></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
	<form name="select" method="post">
	<?php
	if($surveys) {
		foreach($surveys as $s) {
			$date_created = date('d-m-Y',$s->date_created);
			echo "<td width ='200px'><a href='edit.php?sid=$s->id'><font color='blue'>$s->survey_name</font></a></td><td width ='100px'>$date_created</td>";
			if($s->last_modified == $s->date_created) {
				echo "<td>Never</td>";
			} else {
				$last_modified = date('d-m-Y',$s->last_modified);
				echo"<td>$last_modified</td>";
			}
			echo "<td><a href='preview.php?sid=$s->id&sec=1&num=0'><img src='../../includes/images/surveyicons/preview.png'  alt='preview' ></img></a></td>";
			echo "<td><a href='index.php?copy=$s->id'><img src='../../includes/images/surveyicons/copy.png'  alt='copy' ></img></a></td>";
			echo "<td><a href='createsurvey.php?sid=$s->id'><img src='../../includes/images/surveyicons/edit.png'  alt='edit' ></img></a></td>";
			echo "<td><a href='result.php?sid=$s->id'><img src='../../includes/images/surveyicons/results.png'  alt='results' ></img></a></td>";
			echo "<td><a href='schedule.php?sid=$s->id'><img src='../../includes/images/surveyicons/deliver.png'  alt='deliver' ></img></a></td>";
			echo "<td><a href='index.php?delete=$s->id'><img src='../../includes/images/surveyicons/delete.png'  alt='delete' ></img></a></td>";

			/*$no_of_responses = $survey_object->getTotalNumberOfResponses($value->id);
			 if($no_of_responses){
			 echo "<td>$no_of_responses</td></tr>";
			 }else{
			 echo "<td>None</td>";
			 }*/

			echo "</tr>";
		}
	}
	?>
	</form>
</table>
<div class='clear'></div>
<?php require_once '../footer.php'; ?>